﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using yncTech.BusinessObjects;

public partial class Admin_SAPFin_SAPFin002P : AdminBasePage
{
    string[] boxIds;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["boxids"] != null)
        {
            boxIds = Request.QueryString["boxids"].TrimEnd(',').Split(',');
        }
        else
        {
            boxIds = new string[] { Request.QueryString[VBoxLabelInfoMetadata.ColumnNames.BoxID] };
        }
        if (!IsPostBack)
        {
            FinBoxCollection finBoxCollection = new FinBoxCollection();
            finBoxCollection.Query.Where(finBoxCollection.Query.BoxID.In(boxIds));
            finBoxCollection.Query.Load();
            foreach (FinBox box in finBoxCollection)
            {
                if (string.IsNullOrEmpty(box.BoxNo))
                {
                    int index = Business.getBoxIndex(box.BoxID.Value, box.CreatedDttm.Value.Year, box.CompanyName, box.CompanyCode);
                    box.BoxIndex = index;
                    string companyNo = Business.getCompanyNo(box.CompanyName, box.CompanyCode);
                    int receiptCount = Business.getReceiptCount(box.BoxID.Value);
                    box.BoxNo = box.CreatedDttm.Value.Year.ToString() + companyNo + (1000 + receiptCount).ToString().Substring(1, 3) + (10000 + index).ToString().Substring(1, 4);
                }
            }
            finBoxCollection.Save();

            rptLabel.DataSource = finBoxCollection;
            rptLabel.DataBind();

        }
    }
}